package com.dmgameclient.activities;

import java.util.concurrent.Executors;

import com.dmgameclient.R;
import com.dmgameclient.beans.Article;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

/**
 * @name 文章详细内容
 * @Descripation <br>
 *               1、复用页面，在列表上点击时进入该页面。<br>
 *               2、参数的传递、资源的释放。<br>
 * @author 樊俊彬
 * @date 2014-9-20
 * @version 1.0
 */
public class DetailArticleActivity extends Activity {

	private static final String TAG = "DetailArticleActivity";

	// 头部
	private Button headerHome;
	private TextView headerTitle;
	private ProgressBar headerProgress;

	// 正文
	private WebView webView;

	// 评论栏
	private Button fresh;
	private Button comment;
	private Handler handler;

	private Article article;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.detail_article);
		article = (Article) getIntent().getSerializableExtra("articleObject");
		initViews();
		initFrame();
	}

	private void initViews() {
		// 头部
		headerHome = (Button) findViewById(R.id.headerHome);
		headerHome.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		headerTitle = (TextView) findViewById(R.id.headerTitle);
		headerTitle.setText(article.getTitle());

		// 正文
		webView = (WebView) findViewById(R.id.webView1);
		WebSettings settings = webView.getSettings();
		settings.setUseWideViewPort(true);
		settings.setLoadWithOverviewMode(true);
		webView.loadUrl(article.getArcurl());

		// 评论栏
		fresh = (Button) findViewById(R.id.fresh);
		comment = (Button) findViewById(R.id.comment);
		comment.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(DetailArticleActivity.this,
						CommentsActivity.class);
				intent.putExtra("aid", article.getId());
				startActivity(intent);
			}
		});
	}

	@SuppressLint("HandlerLeak")
	private void initFrame() {

		// 刷新页面
		handler = new Handler() {
			public void handleMessage(android.os.Message msg) {
				super.handleMessage(msg);
				if (msg.obj != null) {
					// 显示在界面上并加入到对象中

				}
			}
		};

		// 文章详细数据
		Executors.newSingleThreadExecutor().execute(new Runnable() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				Message msg = Message.obtain();
				handler.sendMessage(msg);
			}
		});
	}
}
